package com.company.oa.meeting.controller;

import com.company.oa.common.api.Result;
import com.company.oa.common.utils.SecurityUtils;
import com.company.oa.meeting.dto.MeetingMinutesDTO;
import com.company.oa.meeting.entity.MeetingMinutes;
import com.company.oa.meeting.service.MeetingMinutesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 会议纪要控制器
 */
@RestController
@RequestMapping("/meeting-minutes")
public class MeetingMinutesController {

    @Autowired
    private MeetingMinutesService meetingMinutesService;

    /**
     * 获取会议纪要
     */
    @GetMapping("/meeting/{meetingId}")
    public Result<MeetingMinutes> getByMeetingId(@PathVariable Long meetingId) {
        MeetingMinutes minutes = meetingMinutesService.getByMeetingId(meetingId);
        return Result.success(minutes);
    }

    /**
     * 保存会议纪要
     */
    @PostMapping
    public Result<Boolean> saveMinutes(@RequestBody @Valid MeetingMinutesDTO minutesDTO) {
        Long userId = SecurityUtils.getUserId();
        String userName = SecurityUtils.getUsername();
        
        boolean result = meetingMinutesService.saveMinutes(minutesDTO, userId, userName);
        return Result.success(result);
    }

    /**
     * 删除会议纪要
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteMinutes(@PathVariable Long id) {
        boolean result = meetingMinutesService.deleteMinutes(id);
        return Result.success(result);
    }
}